package model.staff;

import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import myutil.Connect;

import vo.mixed.CourseListVo;


public class CourseMo{
	ArrayList<CourseListVo> list = new ArrayList<CourseListVo>();
public ArrayList<CourseListVo> getCourseDetails() {
		
		HttpSession session;
		session = ServletActionContext.getRequest().getSession();
		int id=(int) session.getAttribute("user_id");
		String query="SELECT cp.course_id,batch_id,course_professor_id,course_name,course_code,credit,start_date, end_date, lecture_duration FROM course_professor cp, course_details cd WHERE cp.course_id = cd.course_id AND cp.status='Open' AND (professor_id_1 =" + id + " or professor_id_2="+ id + " or professor_id_3="+ id +")";
		System.out.println(query);
		Connect c=new Connect();
		try {
			ResultSet rs=c.getResult(query);
			while(rs.next())
			{
				CourseListVo vo=new CourseListVo();
				vo.setCourse_name(rs.getString("Course_name"));
				vo.setCourse_code(rs.getString("course_code"));
				vo.setCredit(rs.getInt("credit"));
				vo.setStart_date(rs.getInt("start_date"));
				vo.setEnd_date(rs.getInt("end_date"));
				vo.setLecture_duration(rs.getInt("lecture_duration"));
				vo.setCourse_id(rs.getInt("course_id"));
				vo.setBatch_id(rs.getInt("batch_id"));
				vo.setCourse_professor_id(rs.getInt("course_professor_id"));
				list.add(vo);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
}